package logic;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public abstract class Localizator {

	public static String printDate(Date date, String pattern, Locale locale) {
		String s = "";
		final SimpleDateFormat sdf = locale == null ? new SimpleDateFormat(
				pattern) : new SimpleDateFormat(pattern, locale);
		s = sdf.format(date);
		return s;
	}

	public static String printDate(Date date, String pattern) {
		// "yyyy MMMMMMMMM dd"
		String s = "";
		if (pattern == null) {
			s = printDate(date, "yyyy MM dd", null);
		} else {
			s = printDate(date, pattern, null);
		}
		return s;
	}

	public static String printDate(Date date, Locale locale) {
		String s;
		if (locale == null) {
			s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
		} else {
			s = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(
					date);
		}
		return s;
	}

	public static String printDate(Date date) {
		if(date!=null){
		Locale l = null;
		String s = printDate(date, l);
		return s;
		}
		return null;
	}

	public static String printCurrency(double d, Locale locale) {
		NumberFormat nf;
		if (locale == null) {
			nf = NumberFormat.getCurrencyInstance();
		} else {
			nf = NumberFormat.getCurrencyInstance(locale);
		}
		nf.setGroupingUsed(true);
		nf.setMaximumFractionDigits(2);
		nf.setMinimumFractionDigits(2);
		// nf.setMaximumIntegerDigits(10);
		nf.setMinimumIntegerDigits(1);
		String s = "      ".substring(nf.format(d).length() - 8)
				+ nf.format(d);
		return s;
	}

	public static String printCurrency(double d) {
		return printCurrency(d, null);
	}

}
